<template>
	<view class="content">
		<scroll-view style="height: 100vh;" class="wid100" scroll-y="true" @scrolltolower="lower" :refresher-enabled="true">
			<view style="height: 40rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid90 mar bacFFF borRad10 mar-bott30" style="padding: 40rpx 0;">
					<view class="wid90 mar">
						<view class="foSi40 fowe600" style="">{{item.draw.name}}</view>
						<view class="dis disAl disJuB mar-top10 foSi25 coFFF">
							<view style="color: #5A5959;">许愿时间：{{item.createtime | formatDate}}</view>
							<view class="dis disAl disJuC borRad10 xq" @click="tiaozhuan('/pages/wishing/particulars?id='+item.id)">查看详情</view>
						</view>
					</view>
				</view>
			</block>
			<view v-if="list.length == 0" style="height: 140rpx;background-color: #F4EDDD;color: #888;"
				class="dis disAl disJuC">暂无数据</view>
			<view v-if="last_page==0 && list.length > 0" style="height: 140rpx;background-color: #F4EDDD;color: #888;"
				class="dis disAl disJuC">正在加载中...</view>
			<view v-if="last_page==1&& list.length > 0" style="height: 140rpx;background-color: #F4EDDD;color: #888;"
				class="dis disAl disJuC">已经到底了</view>
			<view style="height: 20rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				last_page: 0,
				list: []
			}
		},
		onLoad() {
			this.getOrder()
			this.alioss()
		},
		methods: {
			alioss(){
				var that  = this;
				uni.request({
				    // http://jufeng.tengshuokeji.cn//yonghu/order/order_comments
				    url: that.global.url + '/api/index/alioss',
				    method: "POST",
				    data: {},
				    success(res) {
				        let result = res.data
				        console.log(result)
				        if (result.code == 1) {
				            that.global.ossurl = result.data
							console.log(that.global.ossurl);
							that.ossurl = that.global.ossurl;
				        }
				    }
				})
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				})
			},
			getOrder(){
				var that = this
				uni.request({
					url: that.global.url+'/api/Order', 
					data: {
						type: 3,
						is_pay: '',
						page: that.page,
						size: 10
					},
					header: {
						 'Content-Type': 'application/json' ,//自定义请求头信息
						 'token':uni.getStorageSync('token')
					},
					method:'POST',//请求方式，必须为大写
					success: (res) => {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data);
							that.last_page = result.data.num
							if(that.page == 1){
								that.list = result.data.list
							}else{
								that.list = that.list.concat(result.data.list)
							}
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					}
				})
			},
			lower(e) {
				if(this.last_page == 0){
					this.page++
					this.getOrder()
				}
			},
		},
		filters: {
			formatDate(value) {
				let date = new Date(value * 1000);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				return y + '-' + MM + '-' + d; //年月日
				// return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s; //年月日时分秒
		
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F4EDDD;
	}
	.xq{
		background-color: #C38D5F;
		width: 130rpx;
		height: 50rpx;
	}
</style>
